<?php
session_start();
if(!isset($_SESSION['id'])){
	header('Location:login.php');
}
$connection=mysql_connect("localhost","root","");
mysql_select_db("shenji",$connection);
mysql_query("set names utf8");
$sql4="select count(*) as amount4 from user where username='$_SESSION["username"]'";
$result4=mysql_query($sql4);
$row4=mysql_fetch_array($result4);
$count4=$row4['amount4'];
if($count4==0){
	echo "<script>alert('用户不存在，请重新登录！');top.location.href='./login.php'</script>";
}else{


	$uptype=array("txt");

	$torrent = explode(".", $_FILES["file"]["name"] );
	$fileend = end($torrent);
	$fileend = strtolower($fileend);
	if(!in_array($fileend, $uptype)){
	echo"不允许上传此类型文件！";
	exit;
	}else{

		if($_FILES["file"]["error"] > 0){
	   
	   echo "文件上传错误";
	
		}else{
	 
		 /*$connection=mysql_connect("localhost","root","");
		 mysql_select_db("shenji",$connection);
		 mysql_query("set names utf8");*/
		 $name=$_FILES["file"]["name"];
		 $upload_dir="/var/www/html/upload/ruku/";

		 move_uploaded_file($_FILES["file"]["tmp_name"],$upload_dir.$name);

		 $lines=file_get_contents($upload_dir.$name);

		 $line=split("\n",$lines);

		 	 
		 foreach($line as $li){
		 	
		   $shuju=explode(",",$li);

		   $licesneid=$shuju[0];
		   
		   $beizhu=$shuju[1];

		   $typeid=$_POST['typeid'];
		   if(preg_match("/^[A-Za-z0-9]{3,32}+$/u", $licesneid,$licesneid1)){
		   		//print_r($licesneid1[0]);
		   	$sql2="select * from other_jiekou where licesneid='$licesneid1[0]'";
		   $result2=mysql_query($sql2);
		   //$row2=mysql_num_rows($result2);
		   $row2=mysql_fetch_assoc($result2);
		   $licesneid2=$row2['licesneid'];
		   //echo $licesneid1;
		   $sql3="delete from other_jiekou where licesneid='$licesneid2'";
		   mysql_query($sql3);
		   	$sql="insert into jiekou(licesneid,beizhu,typeid) value('$licesneid1[0]','$beizhu','$typeid')";
		   mysql_query($sql);
		   }

		   /*$sql2="select * from other_jiekou where licesneid='$licesneid'";
		   $result2=mysql_query($sql2);
		   //$row2=mysql_num_rows($result2);
		   $row2=mysql_fetch_assoc($result2);
		   $licesneid1=$row2['licesneid'];
		   //echo $licesneid1;
		   $sql3="delete from other_jiekou where licesneid='$licesneid1'";
		   mysql_query($sql3);

		   $sql="insert into jiekou(licesneid,beizhu,typeid) value('$licesneid','$beizhu','$typeid')";
		   mysql_query($sql);*/
		 }
		
			echo "<script>location='select_jiekou.php';</script>";
		 
		 mysql_close();
		}
	}
}
?>